#pragma once

#include "Serializable.h"
#include "Vectors.h"

class Team;
class ServiceProvider;

struct TeamScore
{
	Team*		m_team;			//team ptr
	size_t		m_score;		//punti
	size_t		m_winMatches;	//partite vinte
	size_t		m_lostMatches;	//partite perse
	size_t		m_drawMathes;	//partite pareggiate
	size_t		m_inGoals;		//goal subiti
	size_t		m_outGoals;		//goal fatti
};
typedef std::vector<TeamScore>	TeamScoreCollection;

class Classification : public Serializable
{
public:
	explicit Classification(ServiceProvider* i_sp);

	void Clear();
	void Initialize(const TeamVec& i_teams);
	void Update(const MatchVec& i_matchScore);

	TeamVec GetSortedTeams() const;
	const MatchVec&	GetMatchesHistory() const;

	virtual	ZStream& Serialize(ZStream& o_stream);
	virtual ZStream& Deserialize(ZStream& i_stream);

	const TeamScoreCollection& GetTeamScores() const;

private:
	struct CompareTeamPtr
	{
		CompareTeamPtr(const Team* i_team) : m_t(i_team){}

		bool operator() (const TeamScore& i_score) const
		{
			return (m_t == i_score.m_team);
		}
		const Team *m_t;
	};

	TeamScoreCollection	m_teamScores;
	MatchVec		m_matchHistory;
	ServiceProvider*	m_sp;
};

inline const MatchVec& Classification::GetMatchesHistory() const
{
	return m_matchHistory;
}

inline const TeamScoreCollection& Classification::GetTeamScores() const
{
	return m_teamScores;
}
